Skip to content

Also reduce term projections #19389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2024
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 6, 2024

We already reduce R { type A = T } # A to T in most situations when we create types. We now also reduce R { val x: S } # x to S if S is a singleton type.

This will simplify types as we go to more term-dependent typing. As a concrete benefit, it will avoid several test-pickling failures due to pickling differences when using dependent types.

@odersky
Copy link
Contributor Author

odersky commented Jan 6, 2024

test performance please

@odersky
Copy link
Contributor Author

odersky commented Jan 6, 2024

@mbovel Performance tests seem to be inoperational

@odersky
Copy link
Contributor Author

odersky commented Jan 12, 2024

I am afraid this PR needs a performance test to be mergeable.

@mbovel
Copy link
Member

mbovel commented Jan 15, 2024

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/19389/ to see the changes.

Benchmarks is based on merging with main (bfabc31)

@odersky
Copy link
Contributor Author

odersky commented Jan 15, 2024

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/19389/ to see the changes.

Benchmarks is based on merging with main (bfabc31)

@odersky
Copy link
Contributor Author

odersky commented Jan 15, 2024

Looks like it does not affect performance, so I think we should adopt this, since it can make dependent types smaller.

@odersky odersky requested a review from mbovel January 15, 2024 17:09
Copy link
Member

@mbovel mbovel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we could write a test for this?

This works:

type T
type T1 = { type A = T } # A
def test = summon[T1 =:= T]

But I can't do:

type S <: Singleton
type S1 = { val x: S } # x
def test = summon[S1 =:= S]
-- [E007] Type Mismatch Error: tests/pos/projection-term-singleton.scala:2:10 --
2 |type S1 = { val x: S } # x
  |          ^^^^^^^^^^^^
  |          Found:    Object{val x: S}
  |          Required: ?{ x: ? }

I guess this is because in R # x, the typer expects R to have a type member named x, not a term member?

I also tried:

import scala.reflect.Selectable.reflectiveSelectable
type S <: Singleton
def test =
  def foo: { val x: S } = ???
  val x: S  = foo.x

and

import scala.reflect.Selectable.reflectiveSelectable
def getX[S, R <: {val x: S}](r: R) = r.x

but both already pass before your PR.

We already reduce `R { type A = T } # A` to `T` in most situations when we
create types. We now also reduce `R { val x: S } # x` to `S` if `S` is a
singleton type.

This will simplify types as we go to more term-dependent typing. As a concrete
benefit, it will avoid several test-pickling failures due to pickling differences
when using dependent types.
@odersky odersky force-pushed the reduce-term-projections branch from 833679a to daa29e6 Compare February 16, 2024 18:41
@odersky odersky merged commit 9e3ce5e into scala:main Feb 17, 2024
@odersky odersky deleted the reduce-term-projections branch February 17, 2024 09:13
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants